Main Page | Class Hierarchy | Class List | Class Members

BustaNetClient Class Reference

Client network interface to Busta'Sandwich. More...

#include <BustaNetClient.h>

List of all members.

Public Member Functions

 BustaNetClient ()
 Constructor.
 ~BustaNetClient ()
 Destructor.
char * init ()
 Initializes the client and prepares it for connection.
char * connect (char *IP, Uint16 serverPort)
 Connects to a server using a given port.
void disconnect ()
 Disconnects from the server.
void flushSocket ()
 Flushes the socket connection to the server of all data.
int getClientID ()
 Returns the network identification number of the client.
int getMaxPlayers ()
 Returns the maximum number of players the server allows.
BustaModelMPGameState * getMPGS ()
 Returns game state information about opponent players.
int getPlayerCount ()
 Returns the number of players on the server.
BustaNetMsgQgetPriorityQ ()
 Returns the server priority message queue.
BustaNetMsgQgetSandwichQ ()
 Returns the special sandwich queue.
char * getServerName ()
 Returns the name of the server connected to.
MPJoinResponsejoinGame (char *playerName)
 Joins the server multiplayer game.
bool processNet ()
 Handles all incoming network data.
void sendCharSelect (BustaModelCharacter character)
 Sends character selection of player.
void sendCursor (BustaModelPosition *cursor)
 Sends current character selection cursor position of player.
void sendGameOver ()
 Notifies the server that the player has lost the game.
void sendOpponentViewReq (int opponentID)
 Tells the server which opponent the player wishes to view.
void sendPing ()
 Sends a simple response request to the server.
void sendReady ()
 Sends a ready message to the server.
void sendSandwich (int opponentID, SpecialSandwich sandwich)
 Sends a spcial sandwich across the network.
void sendState (BustaModelGameState *gs)
 Sends player's game state to the server.


Detailed Description

Client network interface to Busta'Sandwich.

Busta'Sandwich Client for networked multiplayer games.


Constructor & Destructor Documentation

BustaNetClient::BustaNetClient  ) 
 

Constructor.

Initializes variables. A multiplayer gamestate is NOT constructed at this point. Construction of the MPGameState is left to the joinGame() method; joinGame() receives the required information about the server from the server which allows it to know how to construct the MPGameState.

See also:
joinGame()

BustaNetClient::~BustaNetClient  ) 
 

Destructor.

Close any open connections and shutdown SDLNet


Member Function Documentation

char * BustaNetClient::connect char *  IP,
Uint16  serverPort
 

Connects to a server using a given port.

The client initializes a TCP connection with the server on the specified port.

Parameters:
IP The IP address of the server to connect to.
serverPort The port of the server to connect to.
Returns:
A cstring containing information about the connection. Returns NULL on successful connection to the server, or a cstring about connection failure on an unsuccessful connection.

void BustaNetClient::disconnect  ) 
 

Disconnects from the server.

The connection between the server and client is disconnected. Subsequent connections may be made using the client. The multiplayer gamestate is also freed from memory.

void BustaNetClient::flushSocket  ) 
 

Flushes the socket connection to the server of all data.

Empties the socket queue of all data. You may want to do this if you suspect an error in parsing the data from the socket. For instance, if the client is 1 byte off in pulling data from the socket, all the data will be corrupt. It may be better to flush the entire socket and wait for new messages from the server altogether.

int BustaNetClient::getClientID  ) 
 

Returns the network identification number of the client.

All clients in a multiplayer game are given a unique network identification number. This is the means by which clients can distinguish other clients from one another. This method returns the client identification number assigned to this client. By default it is set to -1, and it is reset to -1 when disconnected from a server. When the client has successfully joined a network game the server will assign the client a new number.

Returns:
The network identification number of the client. Is -1 when the client is not a part of a multiplayer game.

int BustaNetClient::getMaxPlayers  ) 
 

Returns the maximum number of players the server allows.

Returns the number of players that the server allowed as a maximum.

Returns:
The maximum number of players allowed on the server

BustaModelMPGameState * BustaNetClient::getMPGS  ) 
 

Returns game state information about opponent players.

Returns a pointer to a BustaModelMPGameState containing information about opponent players. The MPGameState is only instantiated after the client has properly connected and joined a game on a server.

Returns:
A BustaModelMPGameState containing opponent game states. NULL is returned if the multiplayer gamestate has not been yet instantiated.
See also:
BustaModelMPGameState

int BustaNetClient::getPlayerCount  ) 
 

Returns the number of players on the server.

Returns the number of players that are on the server that the client is connected to. This is the number of other players on the server, which does not include the client in the count.

Returns:
The number of players on the server other than this client

BustaNetMsgQ * BustaNetClient::getPriorityQ  ) 
 

Returns the server priority message queue.

Returns the queue of messages from the server. These messages do not cover special sandwiches or game states.

Returns:
A BustaNetMsgQ pointer to a server message queue
See also:
BustaNetMsgQ

BustaNetMsgQ * BustaNetClient::getSandwichQ  ) 
 

Returns the special sandwich queue.

Returns the queue of special sandwiches sent between players in a multiplayer game.

Returns:
A BustaNetMsgQ pointer to a special sandwich message queue
See also:
BustaNetMsgQ

char * BustaNetClient::getServerName  ) 
 

Returns the name of the server connected to.

Returns the name of the server the client is currently connected to.

Returns:
The name of the server

char * BustaNetClient::init  ) 
 

Initializes the client and prepares it for connection.

Initializes SDLNet. Relays any error message back.

Returns:
Returns a cstring containing an error message if SDLNet cannot be initialized. On no error, null is returned.

MPJoinResponse * BustaNetClient::joinGame char *  playerName  ) 
 

Joins the server multiplayer game.

This method attempts to connect the client to the multiplayer game hosted by the server. The client should be connected to the server before running this method. The multiplayer gamestate is instantiated after calling this method if the join was successful.

Parameters:
playerName The name the player wishes to use for the multiplayer game. Names longer than 20 characters will be truncated.
Returns:
A MPJoinResponse with the server's response to the client's connect attempt. Returns null if the client is not already connected to the server.
See also:
connect()

bool BustaNetClient::processNet  ) 
 

Handles all incoming network data.

Processes all data currently queued on the TCP socket. The data is partitioned out into three message containers. Each of these three message containers is accessible through an accompanying accessor method.

Returns:
Returns true if there was activity from the server to process and false otherwise
See also:
getMPGS()

getPriorityQ()

getSandwichQ()

void BustaNetClient::sendCharSelect BustaModelCharacter  character  ) 
 

Sends character selection of player.

Sends the character selection by the player to the server to be sent to all connected players.

Parameters:
character The selected character

void BustaNetClient::sendCursor BustaModelPosition *  cursor  ) 
 

Sends current character selection cursor position of player.

Sends the current position of the player's cursor during multiplayer character selection.

Parameters:
cursor The cursor position of the player's character selection cursor

void BustaNetClient::sendGameOver  ) 
 

Notifies the server that the player has lost the game.

A message is sent to the server to notify it that the player has lost in the current multiplayer game.

void BustaNetClient::sendOpponentViewReq int  opponentID  ) 
 

Tells the server which opponent the player wishes to view.

A message is sent to the server to tell it which opponent the player wishes to have a detailed view of. The detailed view contains information to display the entire screen of the opponent rather than limited brief data.

Parameters:
opponentID The identification of the opponent whom the player wishes to view

void BustaNetClient::sendPing  ) 
 

Sends a simple response request to the server.

Sends a response request to the server. This is useful when the client is unsure whether or not the server is still responding to the client or connected at all. The server follows up with a 'Pong' response.

void BustaNetClient::sendReady  ) 
 

Sends a ready message to the server.

Sending a ready message to the server indicates that the client is ready to begin the multiplayer game. The ready state is visible to all other clients and is used to determine when the server should transition from the accepting connections state.

void BustaNetClient::sendSandwich int  opponentID,
SpecialSandwich  sandwich
 

Sends a spcial sandwich across the network.

A special sandwich is sent from the player to an opposing player.

Parameters:
opponentID The identification of the opponent to whom the player wishes to send the sandwich
sandwich The special sandwich to send

void BustaNetClient::sendState BustaModelGameState *  gs  ) 
 

Sends player's game state to the server.

A BustaModelGameState is converted into structs without pointers to form a packet to send to the server. It makes two sends, a packet identifier message, and the netGameState data packet.

Parameters:
gs The game state of the player


Generated on Sun Aug 14 22:24:57 2005 for BustaSandwich Networking by  doxygen 1.4.2-20050421